package org.teremail.mailbox.search;

import org.teremail.delivery.Envelope;
import org.teremail.delivery.MessageHandler;
import org.teremail.store.Store;

/**
 * A message handler that will index the message passed to it.
 * 
 * @author Michael Barker
 *
 */
public class SearchIndexHandler implements MessageHandler {

    private final MailboxSearch search;
    private final MessageHandler next;
    private final Store store;

    public SearchIndexHandler(MailboxSearch search, Store store, 
            MessageHandler next) {
        this.search = search;
        this.next = next;
        this.store = store;
    }
    
    public void handle(Envelope envelope) {
        search.index(envelope.getMessage(), store);
        next.handle(envelope);
    }

}
